/**
 * @file : main.cpp
 * @author: fenghuwuyu
 * @version 1.0
 * @mail: 3148107006@qq.com
 * @date: 2021年06月22日 星期二 15时51分51秒
 * @brief:
 */

#include<iostream>
#include "femsolver.h"
#include "femFactory.h"

namespace
{
	femsolver* CreateP1()
	{
		return new possion_solver;
	}

	femsolver* CreateP2()
	{
		return new P2possion_solver;
	}

	typedef femsolver* (*femsolverCreator)();
	femsolverCreator crt_P1 = CreateP1;
	femsolverCreator crt_P2 = CreateP2;
}

int main()
{
	femsolverFactory *p1 = femsolverFactory::GetInstance();
	bool B = true;
	std::string P1("P1");
	std::string P2("P2");
	B = p1->Registerfemsolver(P1, crt_P1);
	B = p1->Registerfemsolver(P2, crt_P2);

	// the hole code block is used to read variables.
	
	std::ifstream infile; // infile ifstream 

    infile.open("Inputfile.txt", std::ios::in); // open Inputfil


    std::string method; // method 
    std::string line; // string to storage the getline function
    if (infile.is_open())
    {
        // read the first line 
        getline(infile, line);
        for(int i=0;i<2;i++)
        {
            method.push_back(line[i]);
        }
        line.clear();
    }
    std::cout << "Method: ";
    for(int i=0;i<method.size();i++)
    {
        std::cout << method[i];
    }
    std::cout << std::endl;
    femsolverCreator tool = p1->Find(method);
    femsolver* TOOL = tool();
    TOOL->Compute();

    return 0;

}
